package cn.donting.jme.ohos.system;


import com.jme3.audio.*;
import com.jme3.system.*;
import ohos.agp.components.Component;
import ohos.global.resource.ResourceManager;

import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.logging.Level;


public class JmeOhosSystem extends JmeSystemDelegate {
    private static Component view;

    private static String audioRendererType = AppSettings.ANDROID_OPENAL_SOFT;

    @Override
    public void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width, int height) throws IOException {
        throw new RuntimeException("Stub!");
    }

    @Override
    public void showErrorDialog(String message) {
        throw new RuntimeException("Stub!");
    }

    @Override
    public boolean showSettingsDialog(AppSettings sourceSettings, boolean loadFromRegistry) {
        return false;

    }

    @Override
    public URL getPlatformAssetConfigURL() {
        return Thread.currentThread().getContextClassLoader().getResource("assets/entry/resources/rawfile/com/jme3/asset/HarmonyOs.cfg");

    }

    @Override
    public JmeContext newContext(AppSettings settings, JmeContext.Type contextType) {
        if (settings.getAudioRenderer().equals(AppSettings.ANDROID_MEDIAPLAYER)) {
            audioRendererType = AppSettings.ANDROID_MEDIAPLAYER;
        } else if (settings.getAudioRenderer().equals(AppSettings.ANDROID_OPENAL_SOFT)) {
            audioRendererType = AppSettings.ANDROID_OPENAL_SOFT;
        } else {
            logger.log(Level.INFO, "AudioRenderer not set. Defaulting to OpenAL Soft");
            audioRendererType = AppSettings.ANDROID_OPENAL_SOFT;
        }

        initialize(settings);
        JmeContext ctx = new OGLESContext();
        ctx.setSettings(settings);
        return ctx;
    }


    public static void setView(Component view) {
        JmeOhosSystem.view = view;
    }

    public static Component getView() {
        return view;
    }


    @Override
    public AudioRenderer newAudioRenderer(AppSettings settings) {
        return new AudioRenderer() {
            @Override
            public void setListener(Listener listener) {

            }

            @Override
            public void setEnvironment(Environment environment) {

            }

            @Override
            public void playSourceInstance(AudioSource audioSource) {

            }

            @Override
            public void playSource(AudioSource audioSource) {

            }

            @Override
            public void pauseSource(AudioSource audioSource) {

            }

            @Override
            public void stopSource(AudioSource audioSource) {

            }

            @Override
            public void updateSourceParam(AudioSource audioSource, AudioParam audioParam) {

            }

            @Override
            public void updateListenerParam(Listener listener, ListenerParam listenerParam) {

            }

            @Override
            public float getSourcePlaybackTime(AudioSource audioSource) {
                return 0;
            }

            @Override
            public void deleteFilter(Filter filter) {

            }

            @Override
            public void deleteAudioData(AudioData audioData) {

            }

            @Override
            public void initialize() {

            }

            @Override
            public void update(float v) {

            }

            @Override
            public void pauseAll() {

            }

            @Override
            public void resumeAll() {

            }

            @Override
            public void cleanup() {

            }
        };
    }

    @Override
    public void initialize(AppSettings settings) {

    }

    @Override
    public void showSoftKeyboard(boolean show) {
        throw new RuntimeException("Stub!");
    }
}
